package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.LogBean;
import com.project.dao.LogDao;
import com.project.service.LogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

/**
 * 日志
 */

@Service
@Transactional
public class LogServiceImpl extends ServiceImpl<LogDao, LogBean> implements LogService {
    @Override
    public IPage<LogBean> findAllLog(int pageNo, int pageSize) {
        Page<LogBean> page = new Page<>(pageNo,pageSize);
        IPage<LogBean> iPage = this.page(page);
        return iPage;
    }

    @Override
    public IPage<LogBean> findTime(int pageNo, int pageSize, LocalDate startTime, LocalDate endTime) {
        Page<LogBean> pages = new Page<>(pageNo,pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (startTime!=null){
            wrapper.ge("f_logTime",startTime);
        }
        if (endTime!=null){
            wrapper.le("f_logTime",endTime);
        }
        IPage<LogBean> iPage = this.page(pages,wrapper);
        return iPage;
    }

    @Override
    public void addLog(LogBean logBean) {
        this.save(logBean);
    }
}
